package com.example.asd.puzzle;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        final EditText editText=findViewById(R.id.login_et_nick);
        final EditText editText1=findViewById(R.id.login_et_server);
        final SharedPreferences sp=getSharedPreferences("settings",MODE_PRIVATE);
        editText.setText(sp.getString("nick",""));
        editText1.setText(sp.getString("server","192.168.0.150"));
        Button button=findViewById(R.id.login_bt);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String nick=editText.getText().toString();
                String server=editText1.getText().toString();
                sp.edit().putString("nick",nick).putString("server",server).commit();
                Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                intent.putExtra("nick",nick);
                intent.putExtra("server",server);
                startActivity(intent);
                finish();
            }
        });
    }
}
